package servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import pojo.Warehouse;
import service.AddManager;
import service.WarehouseManager;
import service.impl.WarehouseManagerFactory;

/**
 * Servlet implementation class AddServlet
 */
@WebServlet("/sec/AddServlet")
public class ProductAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	private WarehouseManager manager;
	
    public ProductAddServlet() {
        super();
        manager = WarehouseManagerFactory.getInstance();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		List<Warehouse> list = (List<Warehouse>) request.getSession().getAttribute("ws");
		if(list==null ||list.size()==0){
			list = new ArrayList<Warehouse>();
			list = this.manager.getAllWarehouse();
		}
		for(Warehouse item:list){
			System.out.println(item);
		}
		request.getSession().setAttribute("ws", list);
		
		//跳转到 编辑（添加货品界面）界面
		Logger logger = Logger.getLogger(ProductAddServlet.class);
		logger.info("跳转到 编辑（添加货品界面）界面");
		
		request.getRequestDispatcher("edit.jsp").forward(request, response);
		
	}

}
